home *** CD-ROM | disk | FTP | other *** search
/ Scene Storm / Scene Storm - Volume 1.iso / coding / c / lha_axeman / larc.c < prev    next >
C/C++ Source or Header  |  1995-09-01  |  1KB  |  76 lines

  1. /***********************************************************
  2.     larc.c -- extract *.lzs
  3. ***********************************************************/
  4. #include <stdio.h>
  5. #include "slidehuf.h"
  6.  
  7. #define MAGIC0 18
  8. #define MAGIC5 19
  9.  
  10. static int flag, flagcnt, matchpos;
  11.  
  12. unsigned short decode_c_lzs(void)
  13. {
  14.     if(getbits(1))
  15.   {
  16.         return getbits(8);
  17.     }
  18.   else
  19.   {
  20.         matchpos = getbits(11);
  21.         return getbits(4) + 0x100;
  22.     }
  23. }
  24.  
  25. unsigned short decode_p_lzs(void)
  26. {
  27.     return (loc - matchpos - MAGIC0) & 0x7ff;
  28. }
  29.  
  30. void decode_start_lzs(void)
  31. {
  32.     init_getbits();
  33. }
  34.  
  35. unsigned short decode_c_lz5(void)
  36. {
  37.     int c;
  38.  
  39.     if(flagcnt == 0)
  40.   {
  41.         flagcnt = 8;
  42.         flag = getc(infile);
  43.     }
  44.     flagcnt--;
  45.  
  46.     c = getc(infile);
  47.  
  48.     if((flag & 1) == 0)
  49.   {
  50.         matchpos = c;
  51.         c = getc(infile);
  52.         matchpos += (c & 0xf0) << 4;
  53.         c &= 0x0f;
  54.         c += 0x100;
  55.     }
  56.     flag >>= 1;
  57.     return c;
  58. }
  59.  
  60. unsigned short decode_p_lz5(void)
  61. {
  62.     return (loc - matchpos - MAGIC5) & 0xfff;
  63. }
  64.  
  65. void decode_start_lz5(void)
  66. {
  67.     int i;
  68.  
  69.     flagcnt = 0;
  70.     for(i = 0; i < 256; i++) memset(&text[i * 13 + 18], i, 13);
  71.     for(i = 0; i < 256; i++) text[256 * 13 + 18 + i] = i;
  72.     for(i = 0; i < 256; i++) text[256 * 13 + 256 + 18 + i] = 255 - i;
  73.     memset(&text[256 * 13 + 512 + 18], 0, 128);
  74.     memset(&text[256 * 13 + 512 + 128 + 18], ' ', 128 - 18);
  75. }
  76.